package indy.test.indy;

import java.lang.invoke.CallSite;
import java.lang.invoke.ConstantCallSite;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;


public class BSMFalseSharingTemplate {
    public static void main(String[] args) throws Throwable {
        indy1();
        indy1();
        indy2();
        indy1();
        indy2();
    }

    private static void indy2() {
        throw new AssertionError();
    }

    private static void indy1() {
        throw new AssertionError();
    }
    
    public static void print(Object o) {
        System.out.println(o);
    }
    
    private static final MethodHandle PRINT;
    static {
        try {
            PRINT = MethodHandles.lookup().findStatic(BSMFalseSharingTemplate.class, "print",
                    MethodType.methodType(void.class, Object.class));
        } catch (NoSuchMethodException | IllegalAccessException e) {
            throw new AssertionError(e);
        }
    }
    
    public static CallSite bsm1(@SuppressWarnings("unused") Lookup lookup, @SuppressWarnings("unused") String name, @SuppressWarnings("unused") MethodType type, int arg) {
        MethodHandle target = MethodHandles.insertArguments(PRINT, 0, arg);
        return new ConstantCallSite(target);
    }
    
    public static CallSite bsm2(@SuppressWarnings("unused") Lookup lookup, @SuppressWarnings("unused") String name, @SuppressWarnings("unused") MethodType type, String arg) {
        MethodHandle target = MethodHandles.insertArguments(PRINT, 0, arg);
        return new ConstantCallSite(target);
    }
}
